package homeworkplus.day01;

import java.util.Random;
import java.util.Scanner;

/**
 * @Classname: Test05
 * @Author: bromide
 * @CreateTime: 2022/3/29--19:54
 * @Version: V1.0
 * @Desciption: 随机生成一个5位的英文字母验证码(大小写混搭)
 * 然后将该验证码输出给用户，然后要求用户输入该验证码，大小写不限制。
 * 然后判定用户输入的验证码是否有效(无论用户输入大小写，只要字母都正确即可)。
 */
public class Test05 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder s = new StringBuilder("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz");
        Random random = new Random();
        StringBuilder s1 = new StringBuilder();
        //生成随机验证码
        for (int i = 0; i < 5; i++) {
            int a = random.nextInt(s.length());
            char c = s.charAt(a);
            s1.append(c);
        }
        System.out.println("验证码为:" + s1);
        String s2 = scanner.nextLine();
        if (s2.equalsIgnoreCase(s1.toString().trim())) {
            System.out.println("验证成功！");
        } else {
            System.out.println("验证失败！");
        }

    }
}
